generalized function composition for readable pointfree functions
let o
be the function composition function, and
.
the corresponding infix binary operator, i.e.:
o g f := g . f := \x. g (f x)
let f^n
be the n-th repitition of the function f,
i.e.:
f^0 := id
f^(Sn) := f . f^n
let f_n
be the n-th shift of the function f,
i.e.:
f_0 := id
f_(S n) := o^n f
observe
- repeating composition increases bracket width
o^0 = id = \a b c d e f g. a (b) c d e f g
o^1 = o = \a b c d e f g. a (b c) d e f g
o^2 = o.o = \a b c d e f g. a (b c d) e f g
o^3 = o.o.o = \a b c d e f g. a (b c d e) f g
o^4 = o.o.o.o = \a b c d e f g. a (b c d e f) g
- nesting composition increases bracket offset
o^0 o = o = \a b c d e f g. a (b c) d e f g
o^1 o = o o = \a b c d e f g. a b (c d) e f g
o^2 o = o (o o) = \a b c d e f g. a b c (d e) f g
o^3 o = o (o (o o)) = \a b c d e f g. a b c d (e f) g
o^4 o = o (o (o (o o))) = \a b c d e f g. a b c d (e f) g
therefore o^x o^w
is an arbitrary bracket with
offset x
and width w
, for example:
o^2 o^3 = at place 2, take 3 arguments
= \a b c d e f g. a b c (d e f) g
if we need multiple brackets, we can join them with o… for example, we might want to write the compositon of multiple binary functions in pointfree
\f g h x y z. (f x) (g y) (h z) = o^4 o . o^2 o
= o^2 o . o^3 o
I played with this using http://pointfree.io/.